<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","blno");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_bllist.php";
$FileTemplate  = "ais_transaction_bllist_list.html";

$PageSize      = 10 ;
$TableName     = "bl";
$HTMLGridList  = "BLGrid";

//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

$DBConnection  = new mydb(DB_USER, DB_PASSWORD, DB_NAME2, DB_HOST);	
mysql_select_db(DB_NAME2,$DBMysql);

//Initiate Database Table For Search;
$FCode = GetParam("blCodeSearch","");
$FCurr = GetParam("curr","");
$FVessel = GetParam("vessel","");
$FVoyage = GetParam("voyage","");
$FormName = GetParam("FormName","");
//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM `$TableName` ";
$SQLCount = "SELECT count(*) FROM `$TableName` ";

if ($FCode) 
	if (strlen($WHERE)) $WHERE .= " AND "." BLNO like '".$FCode."%'";
	else $WHERE .= " BLNO like '".$FCode."%'";
if ($FNama) 
	if (strlen($WHERE)) $WHERE .= " AND "." BLNO like '".$FCode."%'";
	else $WHERE .= " BLNO like '".$FCode."%'";
if ($FCurr)
	if (strlen($WHERE)) $WHERE .= " AND "." BLCURRID like '".$FCurr."%'";
	else $WHERE .= " BLCURRID like '".$FCurr."%'";
if ($FVessel)
	if (strlen($WHERE)) $WHERE .= " AND "." BLVESS like '".$FVessel."%'";
	else $WHERE .= " BLVESS like '".$FVessel."%'";
if ($FVoyage)
	if (strlen($WHERE)) $WHERE .= " AND "." BLVOY like '".$FVoyage."%'";
	else $WHERE .= " BLVOY like '".$FVoyage."%'";

	if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE;
	else $WHERE = " WHERE 1";

$SQL = $SQL.$WHERE;
$SQL = $SQL." ORDER BY BLDATE DESC";

$SQLCount = $SQLCount.$WHERE;

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName;	
	for ($x=1;$x<=$PageSize;$x++) {		
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("tblcustomer",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>